<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
                "http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
  <title>Description of VMT_PlotPlanViewQuivers</title>
  <meta name="keywords" content="VMT_PlotPlanViewQuivers">
  <meta name="description" content="This function plots a plan view of the measurement region with a vector">
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="generator" content="m2html &copy; 2005 Guillaume Flandin">
  <meta name="robots" content="index, follow">
  <link type="text/css" rel="stylesheet" href="../m2html.css">
  <script type="text/javascript">
    if (top.frames.length == 0) { top.location = "../index.html"; };
  </script>
</head>
<body>
<a name="_top"></a>
<!-- menu.html trunk -->
<h1>VMT_PlotPlanViewQuivers
</h1>

<h2><a name="_name"></a>PURPOSE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>This function plots a plan view of the measurement region with a vector</strong></div>

<h2><a name="_synopsis"></a>SYNOPSIS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="box"><strong>function [PVdata,fig_planview_handle,log_text] = VMT_PlotPlanViewQuivers(z,A,V,Map,drng,ascale,QuiverSpacing,pvsmwin,pshore,plot_english,varargin) </strong></div>

<h2><a name="_description"></a>DESCRIPTION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre class="comment"> This function plots a plan view of the measurement region with a vector
 field of depth averaged velocity for each processed mean cross section.

 ASC version is for plotting ASCII loaded data. 9/2/09 (also has new
 pvsmwin input for the filter window)

 Added DOQQ plotting capabilities (PRJ, 6-23-10)
 Added english units option
 Added vector data output option in GUI

 User Notes:

 1. Supply z, A, V, and Map for plotting a single mean cross section
 2. Leave z, A, V, and Map blank (i.e. [],[],[],[]) to load multiple,
   (preprocessed and saved) cross sections. In this case, user must supply
   a cell array of filenames, and a path
 3. Leave drng blank (i.e. []) for full depth means or specify
   the a 2 component vector of depths in meters (drng = [ dupper dlower])
   of the depth range to average and plot

 (adapted from code by J. Czuba)

 P.R. Jackson, USGS, 12-10-08 
 Last modified: F.L. Engel, USGS, 2/20/2013</pre></div>

<!-- crossreference -->
<h2><a name="_cross"></a>CROSS-REFERENCE INFORMATION <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
This function calls:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="VMT_LayerAveMean.html" class="code" title="function lam = VMT_LayerAveMean(x,y)">VMT_LayerAveMean</a>	Computes the layer averaged mean of y over the depth range.</li><li><a href="VMT_PlotShoreline.html" class="code" title="function VMT_PlotShoreline(Map)">VMT_PlotShoreline</a>	Plots a shoreline map given the shoreline data structure 'Map' (see</li></ul>
This function is called by:
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="VMT.html" class="code" title="function varargout = VMT(varargin)">VMT</a>	--- THE VELOCITY MAPPING TOOLBOX ---</li></ul>
<!-- crossreference -->

<h2><a name="_subfunctions"></a>SUBFUNCTIONS <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<ul style="list-style-image:url(../matlabicon.gif)">
<li><a href="#_sub1" class="code">function mypostcallback_zoom(obj,evd)</a></li><li><a href="#_sub2" class="code">function mypostcallback_pan(obj,evd)</a></li></ul>

<h2><a name="_source"></a>SOURCE CODE <a href="#_top"><img alt="^" border="0" src="../up.png"></a></h2>
<div class="fragment"><pre>0001 <a name="_sub0" href="#_subfunctions" class="code">function [PVdata,fig_planview_handle,log_text] = VMT_PlotPlanViewQuivers(z,A,V,Map,drng,ascale,QuiverSpacing,pvsmwin,pshore,plot_english,varargin)</a>
0002 <span class="comment">% This function plots a plan view of the measurement region with a vector</span>
0003 <span class="comment">% field of depth averaged velocity for each processed mean cross section.</span>
0004 <span class="comment">%</span>
0005 <span class="comment">% ASC version is for plotting ASCII loaded data. 9/2/09 (also has new</span>
0006 <span class="comment">% pvsmwin input for the filter window)</span>
0007 <span class="comment">%</span>
0008 <span class="comment">% Added DOQQ plotting capabilities (PRJ, 6-23-10)</span>
0009 <span class="comment">% Added english units option</span>
0010 <span class="comment">% Added vector data output option in GUI</span>
0011 <span class="comment">%</span>
0012 <span class="comment">% User Notes:</span>
0013 <span class="comment">%</span>
0014 <span class="comment">% 1. Supply z, A, V, and Map for plotting a single mean cross section</span>
0015 <span class="comment">% 2. Leave z, A, V, and Map blank (i.e. [],[],[],[]) to load multiple,</span>
0016 <span class="comment">%   (preprocessed and saved) cross sections. In this case, user must supply</span>
0017 <span class="comment">%   a cell array of filenames, and a path</span>
0018 <span class="comment">% 3. Leave drng blank (i.e. []) for full depth means or specify</span>
0019 <span class="comment">%   the a 2 component vector of depths in meters (drng = [ dupper dlower])</span>
0020 <span class="comment">%   of the depth range to average and plot</span>
0021 <span class="comment">%</span>
0022 <span class="comment">% (adapted from code by J. Czuba)</span>
0023 <span class="comment">%</span>
0024 <span class="comment">% P.R. Jackson, USGS, 12-10-08</span>
0025 <span class="comment">% Last modified: F.L. Engel, USGS, 2/20/2013</span>
0026 
0027 
0028 warning off
0029 <span class="comment">% disp('Plotting Plan View with Depth-Averaged Velocity Vectors...')</span>
0030 
0031 <span class="comment">%% User Input</span>
0032 
0033 <span class="comment">%QuiverSpacing   = 15;  %Plots a quiver every X emsembles</span>
0034 <span class="comment">%ascale          = 1.5; %Set to 1 for autoscaling and other values for increased or decreased arrow lengths</span>
0035 <span class="keyword">if</span> exist(<span class="string">'plot_english'</span>)==0
0036     plot_english  = 0;
0037     disp(<span class="string">'No units specified, plotting in metric units by default'</span>)
0038 <span class="keyword">end</span>
0039 
0040 <span class="comment">%% Plot Quivers on Area Map</span>
0041 
0042 <span class="keyword">if</span> isnan(drng)
0043     drng = [];
0044 <span class="keyword">end</span>
0045 
0046 windowSize      = pvsmwin; <span class="comment">%Size of window for running average in smoothing of mean vel vectors (set in GUI)</span>
0047 
0048 <span class="comment">% See if PLOT 1 exists already, if so clear the figure</span>
0049 fig_planview_handle = findobj(0,<span class="string">'name'</span>,<span class="string">'Plan View Map'</span>);
0050 
0051 <span class="keyword">if</span> ~isempty(fig_planview_handle) &amp;&amp;  ishandle(fig_planview_handle)
0052     figure(fig_planview_handle); clf
0053 <span class="keyword">else</span>
0054     fig_planview_handle = figure(<span class="string">'name'</span>,<span class="string">'Plan View Map'</span>); clf
0055     <span class="comment">%set(gca,'DataAspectRatio',[1 1 1],'PlotBoxAspectRatio',[1 1 1])</span>
0056 <span class="keyword">end</span>
0057 
0058 <span class="comment">% Turn off the menu bar, and keep only specified tools</span>
0059 disableMenuBar(fig_planview_handle)
0060 
0061 
0062 <span class="keyword">if</span> ~isempty(varargin)
0063     mapmult = true;
0064     zPathName = varargin{2};
0065     zFileName = varargin{1};
0066     zf = length(zFileName);
0067 <span class="keyword">else</span>
0068     mapmult = false;
0069     zf = 1;
0070 <span class="keyword">end</span>
0071 
0072 <span class="comment">% if isempty(z) &amp; isempty(A) &amp; isempty(V) &amp; isempty(Map)</span>
0073 <span class="comment">%     mapmult = 1;</span>
0074 <span class="comment">%     [zPathName,zFileName,zf] = VMT_SelectFiles;  %Have the user select the preprocessed input files</span>
0075 <span class="comment">% else</span>
0076 <span class="comment">%     mapmult = 0;</span>
0077 <span class="comment">%     zf = 1;  %Plot only a single cross section</span>
0078 <span class="comment">% end</span>
0079 
0080 <span class="keyword">for</span> n=1:zf
0081     <span class="keyword">if</span> mapmult
0082         eval([<span class="string">'load '</span> zPathName <span class="string">'\'</span> zFileName{n}]);
0083     <span class="keyword">end</span>
0084     
0085     <span class="keyword">if</span> ~isempty(drng)
0086         indx = find(V.mcsDepth(:,1) &lt; drng(1) | V.mcsDepth(:,1) &gt; drng(2));
0087         
0088         <span class="comment">%Set all data outside depth range to nan</span>
0089         V.mcsX(indx,:) = nan;
0090         V.mcsY(indx,:) = nan;
0091         V.mcsEast(indx,:) = nan;
0092         V.mcsNorth(indx,:) = nan;
0093         
0094 <span class="comment">%         if n == 1</span>
0095 <span class="comment">%             if plot_english</span>
0096 <span class="comment">%                 disp(['Plotting Depth Range ' num2str(drng(1)*3.281) 'ft to ' num2str(drng(2)*3.281) 'ft'])</span>
0097 <span class="comment">%             else</span>
0098 <span class="comment">%                 disp(['Plotting Depth Range ' num2str(drng(1)) 'm to ' num2str(drng(2)) 'm'])</span>
0099 <span class="comment">%             end</span>
0100 <span class="comment">%         end</span>
0101         
0102         clear indx
0103     <span class="keyword">end</span>
0104     
0105    <span class="comment">%Compute mean positions</span>
0106    V.mcsX1 = nanmean(V.mcsX,1);
0107    V.mcsY1 = nanmean(V.mcsY,1);
0108     
0109    <span class="keyword">if</span> 0; <span class="comment">%Compute the depth averaged velocity (straight arithmetic mean--old method)</span>
0110         V.mcsEast1 = nanmean(V.mcsEast,1);
0111         V.mcsNorth1 = nanmean(V.mcsNorth,1);
0112     
0113    <span class="keyword">else</span> <span class="comment">%Compute the depth (or layer) averaged velocity (new method)</span>
0114         V.mcsEast1  = <a href="VMT_LayerAveMean.html" class="code" title="function lam = VMT_LayerAveMean(x,y)">VMT_LayerAveMean</a>(V.mcsDepth,V.mcsEast);
0115         V.mcsNorth1 = <a href="VMT_LayerAveMean.html" class="code" title="function lam = VMT_LayerAveMean(x,y)">VMT_LayerAveMean</a>(V.mcsDepth,V.mcsNorth);
0116    <span class="keyword">end</span>
0117     
0118 
0119     <span class="comment">%Smooth using a running mean defined by WindowSize (averages</span>
0120     <span class="comment">%'2*windowsize+1' ensembles together (centered on node (boxcar filter))</span>
0121     <span class="keyword">if</span> windowSize == 0
0122         V.mcsX1sm     = V.mcsX1;
0123         V.mcsY1sm     = V.mcsY1;
0124         V.mcsEast1sm  = V.mcsEast1;
0125         V.mcsNorth1sm = V.mcsNorth1;
0126     <span class="keyword">else</span>
0127 <span class="comment">%         V.mcsX1sm     = filter(ones(1,windowSize)/windowSize,1,V.mcsX1);</span>
0128 <span class="comment">%         V.mcsY1sm     = filter(ones(1,windowSize)/windowSize,1,V.mcsY1);</span>
0129 <span class="comment">%         V.mcsEast1sm  = filter(ones(1,windowSize)/windowSize,1,V.mcsEast1);</span>
0130 <span class="comment">%         V.mcsNorth1sm = filter(ones(1,windowSize)/windowSize,1,V.mcsNorth1);</span>
0131         
0132         V.mcsEast1sm  = nanmoving_average(V.mcsEast1,windowSize);  <span class="comment">%added 1-7-10, prj</span>
0133         V.mcsNorth1sm = nanmoving_average(V.mcsNorth1,windowSize);
0134         V.mcsX1sm     = V.mcsX1;
0135         V.mcsY1sm     = V.mcsY1;
0136     <span class="keyword">end</span>
0137     
0138     <span class="keyword">for</span> zi = 1 : z
0139         Mag(:,:,zi) = A(zi).Comp.mcsMag(:,:);
0140         <span class="comment">%Mag(:,:,zi) = A(zi).Clean.vMag(:,:);</span>
0141     <span class="keyword">end</span>
0142     numavg = nansum(~isnan(Mag),3);
0143     numavg(numavg==0) = NaN;
0144     enscnt = nanmean(numavg,1);
0145     [I,J] = ind2sub(size(enscnt),find(enscnt&gt;=1));  <span class="comment">%Changed to 1 from 2 (PRJ, 12-12-08)</span>
0146 
0147     et = windowSize+J(1):QuiverSpacing:J(end);  
0148     
0149     <span class="comment">% M(2*n-1,1)=V.mcsX(1,1);</span>
0150     <span class="comment">% M(2*n,1)=V.mcsX(1,end);</span>
0151     <span class="comment">% M(2*n-1,2)=V.mcsY(1,1);</span>
0152     <span class="comment">% M(2*n,2)=V.mcsY(1,end);</span>
0153     <span class="comment">%</span>
0154     <span class="comment">% idx=strfind(zFileName{n},'.');</span>
0155     <span class="comment">% namecut=zFileName{1,n}(2:idx(1)-1);</span>
0156     <span class="comment">%</span>
0157     <span class="comment">% pwr_kml(namecut,latlon);</span>
0158     
0159     <span class="keyword">if</span> n == 1
0160         toquiv(1:493,1:4)=NaN;
0161         lenp = 0;
0162     <span class="keyword">end</span>
0163     
0164     len = length(V.mcsX1sm(1,et));
0165 
0166     toquiv(lenp+1:len+lenp,1)=V.mcsX1sm(1,et);
0167     toquiv(lenp+1:len+lenp,2)=V.mcsY1sm(1,et);
0168     toquiv(lenp+1:len+lenp,3)=nanmean(V.mcsEast1sm(:,et),1);
0169     toquiv(lenp+1:len+lenp,4)=nanmean(V.mcsNorth1sm(:,et),1);
0170 
0171     lenp = length(V.mcsX1sm(1,et))+lenp;
0172 
0173     <span class="comment">% quiverc2wcmap(V.mcsX1sm(1,et),V.mcsY1sm(1,et),nanmean(V.mcsEast1sm(:,et),1),nanmean(V.mcsNorth1sm(:,et),1),0);</span>
0174     <span class="comment">%quiverc(V.mcsX1sm(1,et),V.mcsY1sm(1,et),nanmean(V.mcsEast1sm(:,et),1),nanmean(V.mcsNorth1sm(:,et),1),0)</span>
0175     <span class="comment">%     quiver(V.mcsX1sm(1,et),V.mcsY1sm(1,et),nanmean(V.mcsEast1sm(:,et),1),nanmean(V.mcsNorth1sm(:,et),1),0)</span>
0176     
0177     <span class="keyword">if</span> mapmult
0178         clear A V z Mag numavg enscnt I J latlon idx namecut
0179     <span class="keyword">end</span>
0180 <span class="keyword">end</span>
0181 vr = sqrt(toquiv(:,3).^2+toquiv(:,4).^2);
0182 
0183 <span class="comment">% Save only the good data  %Added 3-28-12 PRJ</span>
0184 gdindx = find(~isnan(vr));
0185 toquiv = toquiv(gdindx,:);
0186 
0187 figure(fig_planview_handle); hold on
0188 <span class="comment">% if pdoqq</span>
0189 <span class="comment">%     VMT_OverlayDOQQ</span>
0190 <span class="comment">% end</span>
0191 <span class="keyword">if</span> pshore
0192     <span class="keyword">if</span> ~isempty(Map) 
0193         <a href="VMT_PlotShoreline.html" class="code" title="function VMT_PlotShoreline(Map)">VMT_PlotShoreline</a>(Map)
0194     <span class="keyword">end</span>
0195 <span class="keyword">end</span>
0196 <span class="comment">%quiverc2wcmap(toquiv(:,1),toquiv(:,2),toquiv(:,3),toquiv(:,4),0,vr,1);</span>
0197 <span class="keyword">if</span> plot_english
0198     quiverc(toquiv(:,1),toquiv(:,2),toquiv(:,3)*0.03281,toquiv(:,4)*0.03281,ascale);  <span class="comment">%*0.03281 to go from cm/s to ft/s</span>
0199     colorbar<span class="comment">%('FontSize',16,'XColor','w','YColor','w');</span>
0200     <span class="keyword">if</span> sum(~isnan(vr)) == 0
0201         errordlg(<span class="string">'No Data in Specified Depth Range'</span>,<span class="string">'Plotting Error'</span>);
0202     <span class="keyword">end</span>
0203     log_text = {sprintf(<span class="string">'   DAV range: %6.3f to %6.3f ft/s'</span>, nanmin(vr)*0.03281,nanmax(vr)*0.03281)};
0204     caxis([nanmin(vr*0.03281) nanmax(vr*0.03281)])  <span class="comment">%resets the color bar axis from 0 to 64 to span the velocity mag range</span>
0205     <span class="keyword">if</span> ~isempty(drng)
0206         title({<span class="string">'Depth-Averaged Velocities (ft/s)'</span>; [<span class="string">'Averaged over depths '</span> num2str(drng(1)*3.281) <span class="string">'ft to '</span> num2str(drng(2)*3.281) <span class="string">'ft'</span>]})<span class="comment">%,'Color','w');</span>
0207     <span class="keyword">else</span>
0208         title(<span class="string">'Depth-Averaged Velocities (ft/s)'</span>)<span class="comment">%,'Color','w');</span>
0209     <span class="keyword">end</span>
0210 <span class="keyword">else</span>  <span class="comment">%plot in metric units</span>
0211     quiverc(toquiv(:,1),toquiv(:,2),toquiv(:,3),toquiv(:,4),ascale);
0212     colorbar<span class="comment">%('FontSize',16,'XColor','w','YColor','w');</span>
0213     <span class="keyword">if</span> sum(~isnan(vr)) == 0
0214         errordlg(<span class="string">'No Data in Specified Depth Range'</span>,<span class="string">'Plotting Error'</span>);
0215     <span class="keyword">end</span>
0216     log_text = {sprintf(<span class="string">'   DAV range: %6.3f to %6.3f m/s'</span>, nanmin(vr),nanmax(vr))};
0217     caxis([nanmin(vr) nanmax(vr)])  <span class="comment">%resets the color bar axis from 0 to 64 to span the velocity mag range</span>
0218     <span class="keyword">if</span> ~isempty(drng)
0219         title({<span class="string">'Depth-Averaged Velocities (cm/s)'</span>; [<span class="string">'Averaged over depths '</span> num2str(drng(1)) <span class="string">'m to '</span> num2str(drng(2)) <span class="string">'m'</span>]})<span class="comment">%,'Color','w');</span>
0220     <span class="keyword">else</span>
0221         title(<span class="string">'Depth-Averaged Velocities (cm/s)'</span>)<span class="comment">%,'Color','w');</span>
0222     <span class="keyword">end</span>
0223 <span class="keyword">end</span>
0224 
0225 xlabel(<span class="string">'UTM Easting (m)'</span>)
0226 ylabel(<span class="string">'UTM Northing (m)'</span>)
0227 figure(fig_planview_handle); box on
0228 <span class="comment">%set(gcf,'Color',[0 0 0]) %[0.2 0.2 0.2]</span>
0229 <span class="comment">%set(gca,'Color',[0.8,0.733,0.533]) %[0.3 0.3 0.3]</span>
0230 set(gca,<span class="string">'DataAspectRatio'</span>,[1 1 1],<span class="string">'PlotBoxAspectRatio'</span>,[1 1 1])
0231 set(gca,<span class="string">'TickDir'</span>,<span class="string">'out'</span>)
0232 
0233 <span class="comment">% Format the ticks for UTM and allow zooming and panning</span>
0234 ticks_format(<span class="string">'%6.0f'</span>,<span class="string">'%8.0f'</span>); <span class="comment">%formats the ticks for UTM</span>
0235 hdlzm = zoom;
0236 set(hdlzm,<span class="string">'ActionPostCallback'</span>,@<a href="#_sub1" class="code" title="subfunction mypostcallback_zoom(obj,evd)">mypostcallback_zoom</a>);
0237 set(hdlzm,<span class="string">'Enable'</span>,<span class="string">'on'</span>);
0238 hdlpn = pan;
0239 set(hdlpn,<span class="string">'ActionPostCallback'</span>,@<a href="#_sub2" class="code" title="subfunction mypostcallback_pan(obj,evd)">mypostcallback_pan</a>);
0240 set(hdlpn,<span class="string">'Enable'</span>,<span class="string">'on'</span>);
0241 
0242 <span class="comment">% Display the figure</span>
0243 <span class="comment">% Hide the figure until the end (this makes the rendering look better)</span>
0244 <span class="comment">%set(fig_planview_handle,'visible','on')</span>
0245 
0246 <span class="comment">%% Save the planview data as output and to an *.anv file with spacing and smoothing (for iRiC)</span>
0247 outmat = zeros(size(toquiv,1),5);
0248 outmat(:,1:2) = toquiv(:,1:2);  <span class="comment">% In metric units</span>
0249 outmat(:,4:5) = toquiv(:,3:4)./100;  <span class="comment">%Converts cm/s to m/s</span>
0250 
0251 <span class="comment">%Screen to ID missing data</span>
0252 goodrows = [];
0253 <span class="keyword">for</span> i = 1:length(outmat)
0254     rowsum = sum(isnan(outmat(i,:)));
0255     <span class="keyword">if</span> rowsum == 0
0256         goodrows = [goodrows; i];
0257     <span class="keyword">end</span>
0258 <span class="keyword">end</span>
0259 
0260 PVdata.outmat = outmat(goodrows,:)';
0261 
0262 <a name="_sub1" href="#_subfunctions" class="code">function mypostcallback_zoom(obj,evd)</a>
0263 ticks_format(<span class="string">'%6.0f'</span>,<span class="string">'%8.0f'</span>); <span class="comment">%formats the ticks for UTM (when zooming)</span>
0264 
0265 <a name="_sub2" href="#_subfunctions" class="code">function mypostcallback_pan(obj,evd)</a>
0266 ticks_format(<span class="string">'%6.0f'</span>,<span class="string">'%8.0f'</span>); <span class="comment">%formats the ticks for UTM (when panning)</span>
0267 
0268</pre></div>
<hr><address>Generated on Tue 30-Apr-2013 10:18:12 by <strong><a href="http://www.artefact.tk/software/matlab/m2html/" target="_parent">m2html</a></strong> &copy; 2005</address>
</body>
</html>